using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BUS;
using Utility;
using Entities;

public partial class Admin_Suatourthamgia : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loaddropdownlist();
            LoadData();

        }
    }
    private void loaddropdownlist()
    {
        dr_tm.DataSource = tbTourmoBUS.GetAll();

        dr_tm.DataValueField = tbTourmoCollumn.matourmo.ToString();
        dr_tm.DataBind();
        dr_tm.Items.Insert(0, new ListItem("All", "0"));

        dr_kh.DataSource = tbKhachhangBUS.GetAll();
        dr_kh.DataTextField = tbKhachhangCollumn.tenkh.ToString();
        dr_kh.DataValueField = tbKhachhangCollumn.makh.ToString();
        dr_kh.DataBind();
        dr_kh.Items.Insert(0, new ListItem("All", "0"));
    }
    private void LoadData()
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            txt_mattg.Text = id.ToString();

            tbTourthamgia  tourtg = tbTourthamgiaBUS .GetByID(id);

            dr_tm .SelectedValue = tourtg.Matourmo .ToString();
            dr_kh.SelectedValue = tourtg.Makh.ToString();

            txt_nl .Text = tourtg.Soluongnguoilon .ToString();
            txt_nn.Text = tourtg.Soluongnguoinho.ToString();



        }
        catch
        {
            Response.Redirect("~/Admin/Danhsachtourthamgia.aspx");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int id = int.Parse(Request.QueryString["id"].ToString());
        tbTourthamgia  ttg = tbTourthamgiaBUS .GetByID(id);

        ttg.Matourmo  = int.Parse(dr_tm .SelectedValue);
        ttg.Makh = int.Parse(dr_kh.SelectedValue);
        ttg.Soluongnguoilon  = int.Parse(txt_nl .Text);
        ttg.Soluongnguoinho  = int.Parse(txt_nn.Text);
        tbTourthamgiaBUS .Update(ttg);

        //    catch
        //    {
        Response.Redirect("~/Admin/Danhsachtourthamgia.aspx");
        //    }

    }
}
